#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Palabre - Main Script
#
# Copyright 2003-2005 Célio Conort
#
# This file is part of Palabre.
#
# Palabre is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
# Palabre is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with program; see the file COPYING. If not,
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.

import os, sys

if hasattr(sys, 'frozen'):
    sys.path.append(os.path.abspath(os.path.dirname(sys.argv[0])))

if __name__ == '__main__':
    
    if not os.path.exists('/etc/palabre.conf'):
        sys.exit("'/etc/palabre.conf' is missing.")
    
    if len(sys.argv) != 2 or sys.argv[1] not in ['start', 'stop', 'restart',
                                                 'status']:
        sys.exit("Usage: %s start|stop|restart|status" % sys.argv[0])

    from palabre import palabreDaemon
    daemon = palabreDaemon.palabreDaemon()
    daemon.control(sys.argv[1])

